package org.nf.shopping.controller;

import com.github.pagehelper.PageInfo;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.nf.shopping.common.vo.UserInfoVo;
import org.nf.shopping.common.vo.ResultVO;
import org.nf.shopping.entity.UserInfo;
import org.nf.shopping.service.UserInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author czl
 * @Date 2024-12-25
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/userInfo")
public class UserInfoController extends BaseController{
    private final UserInfoService userInfoService;

    @GetMapping("/listUserInfo")
    public ResultVO<PageInfo<UserInfo>> userInfoPage(Integer limit, Integer page, String typeName){
        PageInfo<UserInfo> pageInfo = userInfoService.userInfoPage(limit, page, typeName);
        return success(pageInfo);
    }

    @PostMapping("/updateUserInfo")
    public ResultVO updateUserInfo(UserInfo userInfo){
        userInfoService.updateUserInfo(userInfo);
        return success();
    }

    @PostMapping("/deloneUserInfo")
    public ResultVO deloneUserInfo(Integer id){
        userInfoService.deloneUserInfo(id);
        return success();
    }

    @PostMapping("/addUserInfo")
    public ResultVO addUserInfo(UserInfo userInfo){
        userInfoService.addUserInfo(userInfo);
        return success();
    }

    @PostMapping("/getUserInfoList")
    public ResultVO<List<UserInfo>> getUserInfoList(){
        return success(userInfoService.getUserInfoList());
    }

    @PostMapping("/login")
    public ResultVO <UserInfo>login(String userInfoName,String userInfoPwd){
        return success(userInfoService.auto(userInfoName,userInfoPwd));
    }

    @PostMapping("/getAddUserInfo")
    public ResultVO getAddUserInfo(String userInfoName,String userInfoPwd){
        userInfoService.getAddUserInfo(userInfoName,userInfoPwd);
        return success();
    }
}
